using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DataAccessLayer;

public partial class web_Controls_ctrl_vl_left_news_details : System.Web.UI.UserControl
{
    Common _common = null;
    public DataSet _ds;
    string _ma_tin = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        _common = new Common();
        if (Request.Params["id"] != null)
        {
            _ma_tin = Request.Params["id"].ToString();
            LoadNewsDetail(_ma_tin, "");
        }
        if (Request.Params["gid"] != null)
        {
            LoadNewsDetail("",Request.Params["gid"].ToString());
        }
    }
    void LoadNewsDetail(string id,string gid)
    {
        string _sql = "";
        if (id == "" && gid != "")
            _sql = "select * from TinTuc_tin_tuc where ma_loai_tin_tuc = '" + gid + "'";
        else if (id != "" && gid == "")
            _sql = "select * from TinTuc_tin_tuc where ma_tin_tuc = '" + id + "'";
        _ds = _common.ExeceuteDataset(_sql);
        if (_ds.Tables[0].Rows.Count > 0)
        {
            _ma_tin = _ds.Tables[0].Rows[0]["ma_tin_tuc"].ToString();
            lbl_news_detail_tt.Text = string.IsNullOrEmpty(_ds.Tables[0].Rows[0]["tieu_de"].ToString()) ? "" : _ds.Tables[0].Rows[0]["tieu_de"].ToString();
            if (_ds.Tables[0].Rows[0]["tep_tin"].ToString().Trim().Equals("") || _ds.Tables[0].Rows[0]["tep_tin"].ToString().Trim().Contains("noimg.GIF"))
            {
                img_detail.Visible = false;
            }
            else
            {
                img_detail.ImageUrl = "~/" + _ds.Tables[0].Rows[0]["tep_tin"].ToString();
            }
            lbl_news_detail_short.Text = _ds.Tables[0].Rows[0]["mo_ta_ngan"].ToString();
            lbl_news_detail_desc.Text = _ds.Tables[0].Rows[0]["noi_dung"].ToString();
            LoadNewsOther((DateTime)_ds.Tables[0].Rows[0]["ngay_tao"], _ds.Tables[0].Rows[0]["ma_loai_tin_tuc"].ToString());
        }
    }
    void LoadNewsOther(DateTime ngaytao, string maloaitintuc)
    {
        string _sql = "select top 30 *,convert(varchar, tintuc_tin_tuc.ngay_tao, 103) as ngaytao from tintuc_tin_tuc where ma_loai_tin_tuc = '" + maloaitintuc + "' and ngay_tao <= (select ngay_tao from tintuc_tin_tuc where ma_tin_tuc = '"+_ma_tin+"')  order by ngay_tao desc";//and ngay_tao < '" + ngaytao.ToString("MM-dd-yyyy") + "'
        DataSet _ds = _common.ExeceuteDataset(_sql);
        rpt_news_other.DataSource = _ds;
        rpt_news_other.DataBind();
    }
}
